<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_peiorder/model')->方法名();
*/
namespace jy_peiorder;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function up_pass_sendlog(){
		$sendlogs=$this->getall('sendlog',array('daytime'=>0,'uniacid'=>$_SESSION['uniacid']));
		if($sendlogs){
			foreach($sendlogs as $k=>$g){
				$this->update('sendlog',array('daytime'=>strtotime($g['day'])),array('id'=>$g['id'],'uniacid'=>$_SESSION['uniacid']));
			}
		}
		$this->update('sendlog',array('status'=>7),array('daytime <'=>time(),'status'=>0,'uniacid'=>$_SESSION['uniacid']));
		return false;
	}
	public function get_peifee($order=array(),$mid=0,$peisetgoods=array()){
		$mid=$mid?:$_SESSION['uid'];
		$level_id=$this->getcolumn('member',array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']),'level_id');
		if($level_id){
			$level=$this->get('level',array('id'=>$level_id,'uniacid'=>$_SESSION['uniacid']));
		}else{
			if($_SESSION['onemerchid']){
				$level=$this->plugin_setting('default_level'.$_SESSION['onemerchid']);
			}else{
				$level=$this->plugin_setting('default_level');
			}
		}
		$fee_par=$level['fee_par'];
		$goodsnum=pdo_count('jy_weishop_order_goods',array('orderid'=>$order['id']),'id');
		$goods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$order['id']));
		$this->needorder=false;
		$getfee=0;
		$num=0;
		foreach($peisetgoods as $k=>$g){
			$num +=$g['num'];
		}
		foreach($goods as $g){
				$ignore=$this->get('goods',array('goods_id'=>$goods['goodsid'],'uniacid'=>$_SESSION['uniacid']));
				if(!$ignore['id']){
					continue;
				}
				$num -=1;
				if($ignore['ignore']){
					continue;
				}else{
					$goods_commission=$ignore['commissions']?json_decode($ignore['commissions'],true):array();
				}
				foreach($goods_commission as $gc){
					if($gc['level_id']!=$level_id){
						continue;
					}else{
						$goods_per=$gc['fee_per'];
						if(substr($goods_per,-1)=='%'){
							$getfee +=($g['price']*substr($goods_per,0,-1))/100;
						}else{
							$getfee +=$goods_per;
						}
						break;
					}
				}
		}
		if($this->peisetting['peifeetype']){
			//按商品金额百分比计算
		}else{
			//按商品个数计算
		}
		if($num){
			$getfee +=$num*$fee_par;
		}
		return $getfee;
	}
}
?>